package com.longrise.umeng.share;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.longrise.umeng.R;

import static com.umeng.socialize.utils.ContextUtil.getContext;

/**
 * Created by Administrator on 2017/12/20.
 * 友盟分享中弹toast的工具类
 */

public class DialogTools {


    private static Toast mToast;
    /**
     * 兼容较早使用情况
     *
     * @param cxt     上下文，可以传递null
     * @param msg     toast 的msg
     * @param timeOut 延迟时间
     *                在当前App中只有一个Toast实例，toast相关信息
     */
    public static void showToast(Context cxt, String msg, int timeOut) {
        try {
            if (TextUtils.isEmpty(msg) || cxt == null) {
                return;
            }
            if (timeOut <= 0) {
                timeOut = Toast.LENGTH_SHORT;
            }
            View v = View.inflate(getContext(), R.layout.toast_view, null);
            TextView tv = (TextView) v.findViewById(R.id.toast_tv);
            tv.setText(msg);
            if (mToast == null) {
                mToast = new Toast(getContext());
            }
            mToast.setView(v);
            mToast.setDuration(timeOut);
            mToast.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
